from PIL import Image,ImageFont,ImageDraw


def draw_text():
    #加载字体文件
    font_style = ImageFont.truetype("font/SimHei.ttf", 16, encoding="utf-8")
    #创建一张底图,用来绘制文字
    img = Image.new("1",(400,300),color=1)
    draw = ImageDraw.Draw(img)
    #在图片上添加文字
    #fill用来设置绘制文字的颜色,(R,G,B)
    draw.text((100,100),"Python",fill=0,font=font_style)
    draw.text((100,200),"你好",fill=0,font=font_style)
    #draw.text((0, 0), "你好", fill=1, font=font_style)
    #画框
    draw.rectangle([(0, 0), (399, 299)], outline=0,width=8)
    #划线
    draw.line([(0, 50), (399, 50)], fill=0)
    #保存图片
    img.save("img/draw_img_test2.bmp")


draw_text()
